How to use regexp to find the objects which have words "aa", "bb", "cc", "dd", "ee" in any order. It seems that the dxl does not support the regular expression like this: ^(?=.*\baa\b)(?=.*\bbb\b)(?=.*\bcc\b)(?=.*\bdd\b)(?=.*\bee\b).*$ Is there any method I can use to make it happen?
Thanks, Jae JaeHe - Thu Jan 08 09:46:18 EST 2015 |
Re: How to use regexp to find objects? There is probably a more elegant solution but something like this should work
Module m = current
Object o
string strObjTxt
Regexp rAA = regexp2 "aa"
Regexp rBB = regexp2 "bb"
Regexp rCC = regexp2 "cc"
Regexp rDD = regexp2 "dd"
Regexp rEE = regexp2 "ee"
for o in m do {
strObjTxt = o."Object Text"
if (rAA strObjTxt &&
rBB strObjTxt &&
rCC strObjTxt &&
rDD strObjTxt &&
rEE strObjTxt )
{
print identifier o "\n"
}
}
delete rAA
delete rBB
delete rCC
delete rDD
delete rEE
|
Re: How to use regexp to find objects? Martin_Hunter - Mon Jan 12 05:27:56 EST 2015 There is probably a more elegant solution but something like this should work
Module m = current
Object o
string strObjTxt
Regexp rAA = regexp2 "aa"
Regexp rBB = regexp2 "bb"
Regexp rCC = regexp2 "cc"
Regexp rDD = regexp2 "dd"
Regexp rEE = regexp2 "ee"
for o in m do {
strObjTxt = o."Object Text"
if (rAA strObjTxt &&
rBB strObjTxt &&
rCC strObjTxt &&
rDD strObjTxt &&
rEE strObjTxt )
{
print identifier o "\n"
}
}
delete rAA
delete rBB
delete rCC
delete rDD
delete rEE
Thank you, Martin. I think it will work. Is there any way to use one regexp2 to do it all? Because my code has 4 for loops nested, so I want to make it as simple as possible.
Thanks, Jae |
Re: How to use regexp to find objects? JaeHe - Mon Jan 12 09:35:36 EST 2015 Thank you, Martin. I think it will work. Is there any way to use one regexp2 to do it all? Because my code has 4 for loops nested, so I want to make it as simple as possible.
Thanks, Jae I would therefore write a function for this check and call it as required in each loop eg
bool foundWords (string strObjTxt)
{
Regexp rAA = regexp2 "aa"
Regexp rBB = regexp2 "bb"
Regexp rCC = regexp2 "cc"
Regexp rDD = regexp2 "dd"
Regexp rDD = regexp2 "ee"
bool bResult = false
if (rAA strObjTxt &&
rBB strObjTxt &&
rCC strObjTxt &&
rDD strObjTxt &&
rEE strObjTxt)
{
bResult = true
}
delete rAA
delete rBB
delete rCC
delete rDD
delete rEE
return bResult
}
|
Re: How to use regexp to find objects? Martin_Hunter - Mon Jan 12 10:06:18 EST 2015 I would therefore write a function for this check and call it as required in each loop eg
bool foundWords (string strObjTxt)
{
Regexp rAA = regexp2 "aa"
Regexp rBB = regexp2 "bb"
Regexp rCC = regexp2 "cc"
Regexp rDD = regexp2 "dd"
Regexp rDD = regexp2 "ee"
bool bResult = false
if (rAA strObjTxt &&
rBB strObjTxt &&
rCC strObjTxt &&
rDD strObjTxt &&
rEE strObjTxt)
{
bResult = true
}
delete rAA
delete rBB
delete rCC
delete rDD
delete rEE
return bResult
}
Hi Martin, One thing I did not mention here is that the words are going to be dynamic. They could be: "aa", "bb", "cc" or "aa", "bb", "cc", "dd" or "aa", "bb", "cc", "dd", "ee", "ff" or something else. I know I can use for loop to make it, but it may slow down the whole process when there are hundreds of such kind searches going on. Anyway, if there is no other options, I will try your method.
Thanks, Jae
|